package com.alibaba.yygh.oss.controller;

import com.alibaba.yygh.common.result.R;
import com.alibaba.yygh.oss.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * description: FileUploadController
 * @author: gql
 * @date: 2021/11
 */
@Api(description = "阿里云文件管理")
@RestController
@RequestMapping("/admin/oss/file")
public class FileUploadController {

    @Autowired
    private FileService fileService;

    /**
     * 文件上传
     * @param file
     * @return 存储文件的路径
     */
    @ApiOperation(value = "1.文件上传")
    @PostMapping("upload")
    public R upload(@RequestParam("file") MultipartFile file) {
        String uploadUrl = fileService.upload(file);
        return R.ok().message("文件上传成功").data("url", uploadUrl);
    }
}
